﻿using System.Windows;
using System.Windows.Controls;
using PdfSdk.PdfViewer;
using Syncfusion.Windows.PdfViewer;

namespace PdfSdk
{
    public static class WrapperExtensions
    {
        public static readonly DependencyProperty WrapperProperty =
            DependencyProperty.RegisterAttached("Wrapper", typeof(object), typeof(WrapperExtensions), new PropertyMetadata(default(object)));

        public static PdfDocumentViewWrapper GetWrapper(this PdfDocumentView obj)
        {
            if (obj == null)
                return null;

            if (obj.GetValue(WrapperProperty) is PdfDocumentViewWrapper wrapper)
                return wrapper;

            wrapper = new PdfDocumentViewWrapper(obj);
            obj.SetValue(WrapperProperty, wrapper);
            return wrapper;
        }

        public static DocumentViewWrapper GetWrapper(this DocumentView obj)
        {
            if (obj == null)
                return null;

            if (obj.GetValue(WrapperProperty) is DocumentViewWrapper wrapper)
                return wrapper;

            wrapper = new DocumentViewWrapper(obj);
            obj.SetValue(WrapperProperty, wrapper);
            return wrapper;
        }

        public static CustomVPanelWrapper GetWrapper(this CustomVPanel obj)
        {
            if (obj == null)
                return null;

            if (obj.GetValue(WrapperProperty) is CustomVPanelWrapper wrapper)
                return wrapper;

            wrapper = new CustomVPanelWrapper(obj);
            obj.SetValue(WrapperProperty, wrapper);
            return wrapper;
        }

        public static SelectionCanvasWrapper GetWrapper(this InkCanvas obj)
        {
            if (obj == null)
                return null;

            if (obj.GetValue(WrapperProperty) is SelectionCanvasWrapper wrapper)
                return wrapper;

            wrapper = new SelectionCanvasWrapper(obj);
            obj.SetValue(WrapperProperty, wrapper);
            return wrapper;
        }
    }
}
